package com.uuah.server.config.registry;

import java.util.Properties;

import com.uuah.server.api.config.registry.IRegistry;
import com.uuah.server.api.config.registry.IServiceDescriptor;
import com.uuah.server.config.i18n.ServerMessages;
import com.uuah.server.exception.registry.ServiceException;
import com.uuah.server.transport.service.TransportServiceDescriptor;

/**
 *
 * TODO comment ...
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 上午10:03:04
 * @version 1.0.0
 */
public class ServiceDescriptorFactory {
	public static final String PROVIDER_SERVICE_TYPE = "transport";

	public static IServiceDescriptor create(String type, String name,
			Properties props, IRegistry registry, ClassLoader classLoader)
			throws ServiceException {

		IServiceDescriptor sd = null;
		if (type.equals(PROVIDER_SERVICE_TYPE)) {
			try {
				sd = new TransportServiceDescriptor(name, props, registry,
						classLoader);
			} catch (Exception e) {
				throw (IllegalStateException) new IllegalStateException(
						"Cannot create transport " + name).initCause(e);
			}

		} else {
			throw new ServiceException(ServerMessages
					.unrecognisedServiceType(type));
		}

		return sd;
	}
}
